﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FrmMenu.aspx.cs" Inherits="Web.AdminPage.FrmMenu" %>

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div id="tools">
            <div role="form" class="form-inline ">
                <div class="ibox float-e-margins">
                    <div class="form-group">
                        <input type="text" placeholder="父节点" id="Pid" name="Pid" class="form-control">
                    </div>
                    <div class="form-group">
                        <input type="text" placeholder="名称" id="Name" name="Name" class="form-control">
                    </div>
                    <div class="form-group">
                        <input type="text" placeholder="地址" id="Urls" name="Urls" class="form-control">
                    </div>
                    <button class="btn btn-white" type="button" onclick="search(0)">查询</button>
                    <button class="btn btn-white" type="button" onclick="Edit(0)">添加</button>
                </div>
            </div>
        </div>
    </div>
    <div class="ibox float-e-margins">

        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">

                    <div class="example">
                        <table id="tb" data-mobile-responsive="true"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script src="../js/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="../js/content.js?v=1.0.0"></script>
    <!-- Bootstrap table -->
    <script src="../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <!-- Peity -->
    <script src="../js/demo/bootstrap-table-demo.js"></script>
    <script src="../js/plugins/layer/laydate/laydate.js"></script>
    <script>
        function fmartdate_new(timestamp) {

            var date = new Date(parseInt(timestamp.replace("/Date(", "").replace(")/", ""), 10));
            Y = date.getFullYear() + '-';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
            h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
            m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
            s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
            return Y + M + D + h + m + s;
        }
        function formatDate(inputTime) {
            var date = new Date(inputTime);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            var minute = date.getMinutes();
            var second = date.getSeconds();
            minute = minute < 10 ? ('0' + minute) : minute;
            second = second < 10 ? ('0' + second) : second;
            return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
        }
        var tb = $('#tb').bootstrapTable({
            url: "../Hanlder/MenuHandler.ashx?Method=GetList",
            toolbarAlign: "left",
            toolbar: "#tools",
            iconSize: 'outline',
            showColumns: true,
            pagination: true,
            pageSize: 5,
            pageList: [5, 10, 15, 20],
            icons: {
                refresh: 'glyphicon-repeat',
                toggle: 'glyphicon-list-alt',
                columns: 'glyphicon-list'
            },
            columns: [
{
    field: 'Id',
    title: ' ',
    align: 'center',
    width: 'auto'
},
{
    field: 'Pid',
    title: '父节点',
    align: 'center',
    width: 'auto'
},
{
    field: 'Name',
    title: '名称',
    align: 'center',
    width: 'auto'
},
{
    field: 'Urls',
    title: '地址',
    align: 'center',
    width: 'auto'
},
{
    field: 'Id',
    title: '操作',
    align: 'center',
    formatter: function (value, row, index) {

        var str = "";
        str += "<a href=\"javascript:void(0)\" onclick=\"Edit(" + row.Id + ")\">编辑</a>";
        str += "&nbsp;&nbsp;&nbsp;";
        str += "<a href=\"javascript:void(0)\" onclick=\"Del(" + row.Id + ")\">删除</a>";
        return str;


    }
}
            ],
            queryParams: function (params) {
                //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                var temp = {
                    Pid: $("#Pid").val(),
                    Name: $("#Name").val(),
                    Urls: $("#Urls").val(),
                };
                return temp;
            }
        });


        function Edit(Id) {
            var index = parent.layer.open({
                type: 2,
                title: '编辑',
                shadeClose: true,
                shade: 0.8,
                area: ['80%', '60%'],
                content: '../AdminPage/FrmMenuEdit.aspx?Id=' + Id,
                end: function () {

                    parent.layer.close(index);
                    $('#tb').bootstrapTable('refresh');

                }
            });
        }


        function search() {
            $('#tb').bootstrapTable('refresh');
        }
        function getAllcks(callback) {
            var getSelectRows = $.map($("#tb").bootstrapTable('getSelections'), function (row) {
                return row;
            });
            var ids = new Array();//定义js数组用于存放自己所需的值
            for (var i = 0; i < getSelectRows.length; i++) {
                ids[i] = getSelectRows[i].Id;
            }
            callback(ids);
        }

        //do_frozen

        function Del(Id) {
            $.ajax({
                type: 'post',
                url: '../Hanlder/MenuHandler.ashx?Method=Del',
                data: { Id: Id },

                success: function (data) {
                    var res = $.parseJSON(data);

                    if (res.states == 0) {
                        parent.layer.msg("操作成功");
                    } else {
                        parent.layer.msg(res.msg);
                    }
                    tb.bootstrapTable('refresh');
                }
            });
        }


    </script>
</body>
</html>
